home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol04 / 01b / macsl / mpmframe.c < prev    next >
C/C++ Source or Header  |  1988-10-03  |  20KB  |  624 lines

  1. /*-----------------------------------------------------------------*/
  2. /* MpmFrame.c                                                      */
  3. /* Frame window functions                                          */
  4. /*-----------------------------------------------------------------*/
  5.  
  6. #include "MacPM.h"
  7.  
  8. /*-----------------------------------------------------------------*/
  9.  
  10. LOCAL BOOL      MpmFrameFixCtl( HWND hwndFrame, ULONG flFrameFlags,
  11.                                 ULONG flFlagMask, PVOID pCtlData,
  12.                                 PSZ pszClass, PHWND pahwndCtls,
  13.                                 USHORT usFid, ULONG flCtlStyle );
  14. LOCAL MRESULT   MpmFrameFormat( HWND hwndFrame );
  15. LOCAL MRESULT   MpmFrameUpdate( HWND hwndFrame, ULONG flFrameFlags );
  16. LOCAL SHORT     MpmFrameQueryCtls( HWND hwndFrame,
  17.                                    PHWND pahwndCtls );
  18. LOCAL VOID      MpmZoomWindow( HWND hwnd, SHORT sPart );
  19.  
  20. /*-----------------------------------------------------------------*/
  21. /* Create a frame window and the specified frame controls.         */
  22. /*-----------------------------------------------------------------*/
  23.  
  24. HWND APIENTRY WinCreateStdWindow( hwndParent, flStyle, pCtlData,
  25.                                   pszClassClient, pszTitle,
  26.                                   flStyleClient, hmod, idResources,
  27.                                   phwndClient )
  28.     HWND        hwndParent;
  29.     ULONG       flStyle, flStyleClient;
  30.     PVOID       pCtlData;
  31.     PSZ         pszClassClient, pszTitle;
  32.     HMODULE     hmod;
  33.     USHORT      idResources;
  34.     PHWND       phwndClient;
  35. {
  36.     HWND        hwndFrame, hwndClient;
  37.     SHORT       x, y, cx, cy;
  38.     ULONG       flFrameFlags;
  39.  
  40.     /* Pick up frame flags, take care of special hwndParent values */
  41.  
  42.     flFrameFlags = ( pCtlData ? *(PULONG)pCtlData : 0 );
  43.  
  44.     if( ! hwndParent || hwndParent == HWND_DESKTOP )
  45.       hwndParent = _hwndDesktop;
  46.  
  47.     ASSERT( hwndParent == _hwndDesktop,
  48.             "WinCreateStdWindow: Must be a top level window" );
  49.     ASSERT( ! hmod,
  50.             "WinCreateStdWindow: hmod must be NULL" );
  51.     ASSERT( ! (flStyle & WS_CLIPCHILDREN),
  52.             "WinCreateStdWindow: WS_CLIPCHILDREN not allowed" );
  53.  
  54.     /* Assign default position if visible */
  55.  
  56.     if( flStyle & WS_VISIBLE )
  57.     {
  58.       x = 10;       /* TEMP HACK */
  59.       y = screenBits.bounds.bottom - 200;
  60.       cx = 250;
  61.       cy = 150;
  62.     }
  63.     else
  64.       x = y = cx = cy = 0;
  65.  
  66.     /* Create the frame window itself */
  67.  
  68.     hwndFrame =
  69.       WinCreateWindow( hwndParent, WC_FRAME, _szNull,
  70.                        flStyle & ~WS_VISIBLE, x, y, cx, cy,
  71.                        NULL, HWND_TOP, idResources, pCtlData, NULL );
  72.  
  73.     if( ! hwndFrame )
  74.       return NULL;
  75.  
  76.     /* Create frame controls according to flFrameFlags */
  77.  
  78.     MpmFrameUpdate( hwndFrame, flFrameFlags );
  79.  
  80.     /* Create client window if requested */
  81.  
  82.     if( pszClassClient && *pszClassClient )
  83.     {
  84.       *phwndClient = hwndClient =
  85.         WinCreateWindow(
  86.           hwndFrame, pszClassClient, _szNull, flStyleClient,
  87.           0, 0, 0, 0, hwndFrame, HWND_BOTTOM, FID_CLIENT, NULL, NULL
  88.         );
  89.       if( ! hwndClient )
  90.         goto exitDestroy;
  91.     }
  92.  
  93.     /* Create menu and initialize title */
  94.  
  95.     if( flFrameFlags & FCF_MENU )
  96.       if( ! MpmMenuLoad( hwndFrame, idResources ) )
  97.         goto exitDestroy;
  98.  
  99.     if( flFrameFlags & FCF_TITLEBAR )
  100.       WinSetWindowText( hwndFrame, pszTitle );
  101.  
  102.     /* Make window visible if requested */
  103.  
  104.     if( flStyle & WS_VISIBLE )
  105.     {
  106.       WinSendMsg( hwndFrame, WM_FORMATFRAME, 0L, 0L );
  107.       WinShowWindow( hwndFrame, TRUE );
  108.     }
  109.  
  110.     return hwndFrame;
  111.  
  112. exitDestroy:
  113.     if( pszClassClient && *pszClassClient )
  114.       *phwndClient = NULL;
  115.     WinDestroyWindow( hwndFrame );
  116.     return NULL;
  117. }
  118.  
  119. /*-----------------------------------------------------------------*/
  120. /* Create or destroy one frame control for MpmFrameUpdate.         */
  121. /*-----------------------------------------------------------------*/
  122.  
  123. LOCAL BOOL MpmFrameFixCtl( hwndFrame, flFrameFlags, flFlagMask,
  124.                              pCtlData, pszClass, pahwndCtls, usFid,
  125.                              flCtlStyle )
  126.     HWND        hwndFrame;
  127.     ULONG       flFrameFlags, flFlagMask, flCtlStyle;
  128.     PVOID       pCtlData;
  129.     PSZ         pszClass;
  130.     PHWND       pahwndCtls;
  131.     USHORT      usFid;
  132. {
  133.     PHWND       phwnd;
  134.  
  135.     ASSERT( usFid >= FID_CTL_MIN && usFid <= FID_CTL_MAX,
  136.             "MpmFrameFixCtl: bad usFid" );
  137.  
  138.     phwnd = pahwndCtls + usFid - FID_CTL_MIN;
  139.  
  140.     if( flFrameFlags & flFlagMask )
  141.     {
  142.       if( *phwnd )
  143.         return TRUE;
  144.  
  145.       *phwnd =
  146.         WinCreateWindow( hwndFrame, pszClass, _szNull, flCtlStyle,
  147.                          0, 0, 0, 0, hwndFrame, HWND_BOTTOM,
  148.                          usFid, pCtlData, NULL );
  149.       return !! *phwnd;
  150.     }
  151.     else  /* ! ( flFrameFlags & flFlagMask ) */
  152.     {
  153.       if( ! *phwnd )
  154.         return TRUE;
  155.       WinDestroyWindow( *phwnd );
  156.       *phwnd = NULL;
  157.       return TRUE;
  158.     }
  159. }
  160.  
  161. /*-----------------------------------------------------------------*/
  162. /* Adjust the positions of all the frame controls (and client      */
  163. /* window) in hwndFrame according to its current size, by setting  */
  164. /* up a SWP structure and calling WinSetMultWindowPos.             */
  165. /*-----------------------------------------------------------------*/
  166.  
  167. LOCAL MRESULT MpmFrameFormat( hwndFrame )
  168.     HWND        hwndFrame;
  169. {
  170.     HWND        ahwnd[FID_CTL_COUNT];
  171.     SWP         aswp[FID_CTL_COUNT];
  172.     PHWND       phwnd;
  173.     SHORT       i;
  174.     LONG        flStyle;
  175.     RECTL       rclFrame, rclClient, rclNewClient, rclVert, rclHorz;
  176.     Rect        rectAdj;
  177.  
  178.     /* Clear the SWP structure, get the list of frame controls */
  179.  
  180.     memzero( &aswp );
  181.  
  182.     if( ! MpmFrameQueryCtls( hwndFrame, ahwnd ) )
  183.       return 0L;
  184.  
  185.     for( i = 0;  i < FID_CTL_COUNT;  i++ )
  186.       aswp[i].hwnd = ahwnd[i];
  187.  
  188.     ASSERT( ahwnd[I_CLIENT],
  189.             "MpmFrameFormat: Must have client window" );
  190.  
  191.     /* Give the client window a shot at if it wants to take over */
  192.             
  193.     if( WinSendMsg( ahwnd[I_CLIENT], WM_FORMATFRAME, 0, 0 ) )
  194.       return MRFROMLONG(1);
  195.  
  196.     /* Pick up the frame window size and style */
  197.  
  198.     flStyle = MYWNDOF(hwndFrame).flStyle;
  199.     rectAdj = MYWNDOF(hwndFrame).rectAdj;
  200.     WinQueryWindowRect( hwndFrame, &rclFrame );
  201.     
  202.     if( ahwnd[I_SIZEBORDER] )
  203.     {
  204.       ASSERT( ahwnd[I_VERTSCROLL] || ahwnd[I_HORZSCROLL],
  205.               "MpmFrameFormat: FID_SIZEBORDER requires scroll bar" );
  206.     }
  207.  
  208.     /* Take a first cut at the client window position/size */
  209.  
  210.     rclClient.xLeft   = rclFrame.xLeft   + rectAdj.left;
  211.     rclClient.xRight  = rclFrame.xRight  + rectAdj.right;
  212.     rclClient.yBottom = rclFrame.yBottom - rectAdj.bottom;
  213.     rclClient.yTop    = rclFrame.yTop    - rectAdj.top;
  214.  
  215.     rclNewClient = rclClient;
  216.  
  217.     /* Position the vertical scroll bar */
  218.  
  219. #define swp aswp[I_VERTSCROLL]
  220.     if( ahwnd[I_VERTSCROLL] )
  221.     {
  222.       swp.cx = _alSysVal[SV_CXVSCROLL];
  223.       swp.x = rclNewClient.xRight =
  224.         rclClient.xRight - swp.cx + _alSysVal[SV_CXBORDER];
  225.       swp.y = rclClient.yBottom - _alSysVal[SV_CYBORDER];
  226.       if( ahwnd[I_HORZSCROLL] || ahwnd[I_SIZEBORDER] )
  227.         swp.y += _alSysVal[SV_CYHSCROLL] - _alSysVal[SV_CYBORDER];
  228.       swp.cy = rclClient.yTop - swp.y + _alSysVal[SV_CYBORDER];
  229.       swp.fs = SWP_MOVE | SWP_SIZE;
  230.     }
  231. #undef swp
  232.  
  233.     /* Position the horizontal scroll bar */
  234.  
  235. #define swp aswp[I_HORZSCROLL]
  236.     if( ahwnd[I_HORZSCROLL] )
  237.     {
  238.       swp.cy = _alSysVal[SV_CYHSCROLL];
  239.       swp.y = rclClient.yBottom - _alSysVal[SV_CYBORDER];
  240.       rclNewClient.yBottom =
  241.         rclClient.yBottom + swp.cy - _alSysVal[SV_CYBORDER];
  242.       swp.x = rclClient.xLeft - _alSysVal[SV_CXBORDER];
  243.       swp.cx = rclClient.xRight - swp.x + _alSysVal[SV_CXBORDER];
  244.       if( ahwnd[I_VERTSCROLL] || ahwnd[I_SIZEBORDER] )
  245.         swp.cx -= _alSysVal[SV_CXVSCROLL] - _alSysVal[SV_CXBORDER];
  246.       swp.fs = SWP_MOVE | SWP_SIZE;
  247.     }
  248. #undef swp
  249.  
  250.     /* Now that we know which (if any) scroll bars are present,
  251.        set the final client size */
  252.  
  253. #define swp aswp[I_CLIENT]
  254.     if( ahwnd[I_CLIENT] )
  255.     {
  256.       swp.x = rclNewClient.xLeft;
  257.       swp.cx = rclNewClient.xRight - rclNewClient.xLeft;
  258.       swp.y = rclNewClient.yBottom;
  259.       swp.cy = rclNewClient.yTop - rclNewClient.yBottom;
  260.       swp.fs = SWP_MOVE | SWP_SIZE;
  261.     }
  262. #undef swp
  263.  
  264.     /* Everything's calculated, play bumper car with the windows */
  265.  
  266.     WinSetMultWindowPos( (HAB)NULL, &aswp[0], FID_CTL_COUNT );
  267.  
  268.     return MRFROMSHORT(TRUE);
  269. }
  270.  
  271. /*-----------------------------------------------------------------*/
  272. /* Handy function to get the list of controls in a frame window    */
  273. /*-----------------------------------------------------------------*/
  274.  
  275. SHORT MpmFrameQueryCtls( hwndFrame, pahwndCtls )
  276.     HWND        hwndFrame;
  277.     PHWND       pahwndCtls;
  278. {
  279.     return WinMultWindowFromIDs( hwndFrame, pahwndCtls,
  280.                                  FID_CTL_MIN, FID_CTL_MAX );
  281. }
  282.  
  283. /*-----------------------------------------------------------------*/
  284. /* Create or destroy the appropriate frame controls in hwndFrame   */
  285. /* according to the bits in flFrameFlags.                          */
  286. /*-----------------------------------------------------------------*/
  287.  
  288. LOCAL MRESULT MpmFrameUpdate( hwndFrame, flFrameFlags )
  289.     HWND        hwndFrame;
  290.     ULONG       flFrameFlags;
  291. {
  292.     BOOL        fOK;
  293.  
  294.     HWND        ahwndCtls[FID_CTL_COUNT];
  295.     SBCDATA     sbcd;
  296.  
  297.     MpmFrameQueryCtls( hwndFrame, ahwndCtls );
  298.  
  299.     sbcd.cb = sizeof(sbcd);
  300.     sbcd.sHilite = FALSE;
  301.     sbcd.posFirst = sbcd.posLast = sbcd.posThumb = 0;
  302.  
  303.     fOK =
  304.       (
  305.         MpmFrameFixCtl( hwndFrame, flFrameFlags, FCF_SIZEBORDER, NULL,
  306.                         WC_SIZEBORDER, ahwndCtls, FID_SIZEBORDER,
  307.                         WS_PARENTCLIP )
  308.       &&
  309.         MpmFrameFixCtl( hwndFrame, flFrameFlags, FCF_TITLEBAR, NULL,
  310.                         WC_TITLEBAR, ahwndCtls, FID_TITLEBAR,
  311.                         WS_PARENTCLIP )
  312.       &&
  313.         MpmFrameFixCtl( hwndFrame, flFrameFlags, FCF_SYSMENU, NULL,
  314.                         WC_MENU, ahwndCtls, FID_SYSMENU,
  315.                         WS_PARENTCLIP | MS_ACTIONBAR | MS_TITLEBUTTON )
  316.       &&
  317.         MpmFrameFixCtl( hwndFrame, flFrameFlags, FCF_MINMAX, NULL,
  318.                         WC_MENU, ahwndCtls, FID_MINMAX,
  319.                         WS_PARENTCLIP | MS_ACTIONBAR | MS_TITLEBUTTON )
  320.       &&
  321.         MpmFrameFixCtl( hwndFrame, flFrameFlags, FCF_VERTSCROLL, &sbcd,
  322.                         WC_SCROLLBAR, ahwndCtls, FID_VERTSCROLL,
  323.                         WS_PARENTCLIP | SBS_VERT )
  324.       &&
  325.         MpmFrameFixCtl( hwndFrame, flFrameFlags, FCF_HORZSCROLL, &sbcd,
  326.                         WC_SCROLLBAR, ahwndCtls, FID_HORZSCROLL,
  327.                         WS_PARENTCLIP | SBS_HORZ )
  328.       &&
  329.         MpmFrameFixCtl( hwndFrame, flFrameFlags, FCF_MENU, NULL,
  330.                         WC_MENU, ahwndCtls, FID_MENU,
  331.                         WS_PARENTCLIP | MS_ACTIONBAR )
  332.       );
  333.  
  334.     ASSERT( fOK,
  335.             "MpmFrameUpdate: MpmFrameFixCtl failed" );
  336.  
  337.     if( ! ahwndCtls[I_CLIENT] )
  338.       return MRFROMLONG(TRUE);
  339.  
  340.     return WinSendMsg( ahwndCtls[I_CLIENT], WM_FORMATFRAME, 0, 0 );
  341. }
  342.  
  343. /*-----------------------------------------------------------------*/
  344. /* Find out if pszClassName is the frame window class.             */
  345. /*-----------------------------------------------------------------*/
  346.  
  347. LOCAL BOOL MpmIsFrameClass( pszClassName )
  348.     PSZ         pszClassName;
  349. {
  350.     return strcmp( pszClassName, "#1" ) == 0;
  351. }
  352.  
  353. /*-----------------------------------------------------------------*/
  354. /* Handle a WM_SYSCOMMAND/SC_MAXIMIZE request for a frame window.  */
  355. /*-----------------------------------------------------------------*/
  356.  
  357. LOCAL VOID MpmZoomWindow( hwnd, sPart )
  358.     HWND        hwnd;
  359.     SHORT       sPart;
  360. {
  361.     PMYWND      pwnd;
  362.     WindowPeek  pwin;
  363.     SWP         swp;
  364.     Rect*       prect;
  365.  
  366.     pwin = MYWNDOF(hwnd).pwin;
  367.  
  368.     /* Get the old size for the WM_SIZE message */
  369.  
  370.     WinQueryWindowPos( hwnd, &swp );
  371.  
  372.     /* Do the Mac zooming */
  373.  
  374.     thePort = &pwin->port;
  375.     EraseRect( &pwin->port.portRect );
  376.     ZoomWindow( pwin, sPart, FALSE );
  377.  
  378.     /* Bring the MYWND information up to date */
  379.  
  380.     pwnd = PMYWNDOF(hwnd);
  381.     prect = &(**pwin->strucRgn).rgnBBox;
  382.  
  383.     pwnd->x  = prect->left;
  384.     pwnd->y  = (SHORT)_alSysVal[SV_CYSCREEN] - prect->bottom;
  385.     pwnd->cx = prect->right - prect->left;
  386.     pwnd->cy = prect->bottom - prect->top;
  387.  
  388.     /* Send the WM_MOVE and WM_SIZE messages */
  389.  
  390.     if( MYCLASSOF(hwnd).class.flClassStyle & CS_MOVENOTIFY )
  391.       WinSendMsg( hwnd, WM_MOVE, 0, 0 );
  392.  
  393.     WinSendMsg( hwnd, WM_SIZE,
  394.                 MPFROM2SHORT( swp.cx, swp.cy ),
  395.                 MPFROM2SHORT( MYWNDOF(hwnd).cx, MYWNDOF(hwnd).cy ) );
  396. }
  397.  
  398. /*-----------------------------------------------------------------*/
  399. /* Window function for the frame window class.                     */
  400. /*-----------------------------------------------------------------*/
  401.  
  402. MRESULT EXPENTRY MpmFnwpFrame( hwnd, msg, mp1, mp2 )
  403.     HWND        hwnd;
  404.     USHORT      msg;
  405.     MPARAM      mp1;
  406.     MPARAM      mp2;
  407. {
  408.     HWND        hwndClient, hwndTitle;
  409.     HPS         hps;
  410.  
  411.     if( ! MpmValidateWindow(hwnd) )
  412.       return 0L;
  413.  
  414.     switch( msg )
  415.     {
  416.       /* these msgs are passed through to client window */
  417.       case WM_COMMAND:
  418.       case WM_HSCROLL:
  419.       case WM_INITMENU:
  420.       case WM_VSCROLL:
  421.         hwndClient = WinWindowFromID( hwnd, FID_CLIENT );
  422.         if( ! hwndClient )
  423.           return 0L;
  424.         return WinSendMsg( hwndClient, msg, mp1, mp2 );
  425.  
  426.       case WM_FORMATFRAME:
  427.         return MpmFrameFormat( hwnd );
  428.  
  429.       case WM_PAINT:
  430.         hwndClient = WinWindowFromID( hwnd, FID_CLIENT );
  431.         if( hwndClient &&
  432.             ! WinSendMsg( hwndClient, WM_ERASEBACKGROUND, 0, 0 ) )
  433.         {
  434.           hps = WinGetPS( hwndClient );  /* this is probably wrong! */
  435.           ASSERT( hps,
  436.                   "MpmFnwpFrame: WinGetPS failed" );
  437.           GpiErase( hps );
  438.           WinReleasePS( hps );
  439.         }
  440.         return 0L;
  441.  
  442.       case WM_QUERYWINDOWPARAMS:
  443.       case WM_SETWINDOWPARAMS:
  444.         hwndTitle = WinWindowFromID( hwnd, FID_TITLEBAR );
  445.         if( ! hwndTitle )
  446.           return 0L;
  447.         return WinSendMsg( hwndTitle, msg, mp1, mp2 );
  448.  
  449.       case WM_SIZE:
  450.         WinSendMsg( hwnd, WM_FORMATFRAME, 0L, 0L );
  451.         return 0L;
  452.  
  453.       case WM_SYSCOMMAND:
  454.         switch( COMMANDMSG(&msg)->cmd )
  455.         {
  456.           case SC_CLOSE:
  457.             hwndClient = WinWindowFromID( hwnd, FID_CLIENT );
  458.             WinSendMsg( hwndClient ? hwndClient : hwnd,
  459.                         WM_CLOSE, 0L, 0L );
  460.             return 0L;
  461.  
  462.           case SC_MAXIMIZE:
  463.             MpmZoomWindow( hwnd, inZoomOut );
  464.             return 0L;
  465.  
  466.           case SC_RESTORE:
  467.             MpmZoomWindow( hwnd, inZoomIn );
  468.             return 0L;
  469.         }
  470.         return 0L;
  471.  
  472.       case WM_UPDATEFRAME:
  473.         hwndClient = WinWindowFromID( hwnd, FID_CLIENT );
  474.         if( hwndClient &&
  475.             WinSendMsg( hwndClient, WM_UPDATEFRAME, 0, 0 ) )
  476.           return MRFROMLONG(TRUE);
  477.         return MpmFrameUpdate( hwnd, LONGFROMMP(mp1) );
  478.     }
  479.     
  480.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  481. }
  482.  
  483. /*-----------------------------------------------------------------*/
  484. /* Window function for the sizing border (size box) window class.  */
  485. /*-----------------------------------------------------------------*/
  486.  
  487. MRESULT EXPENTRY MpmFnwpSizeBorder( hwnd, msg, mp1, mp2 )
  488.     HWND        hwnd;
  489.     USHORT      msg;
  490.     MPARAM      mp1;
  491.     MPARAM      mp2;
  492. {
  493.     LONG        lNewPoint;
  494.     Point       point, pointOld;
  495.     Rect        rect;
  496.     WindowPeek  pwin;
  497.     SWP         swp;
  498.     HWND        hwndFrame;
  499.  
  500.     if( ! MpmValidateWindow(hwnd) )
  501.       return FALSE;
  502.  
  503.     switch( msg )
  504.     {
  505.       /* Let user resize the window; notify it of the new size */
  506.  
  507.       case WM_BUTTON1DOWN:
  508.         hwndFrame = MYWNDOF(hwnd).hwndOwner;
  509.         pwin = MYWNDOF(hwnd).pwin;
  510.         pointOld.h = pwin->port.portRect.right;
  511.         pointOld.v = pwin->port.portRect.bottom;
  512.         WinQueryWindowPos( hwndFrame, &swp );
  513.         swp.fs &= ~( SWP_ACTIVATE | SWP_DEACTIVATE );
  514.         point.h = MOUSEMSG(&msg)->x;
  515.         point.v = _alSysVal[SV_CYSCREEN] - MOUSEMSG(&msg)->y;
  516.         /* should do a WM_QUERYMINMAXINFO... */
  517.         rect.top = 100;
  518.         rect.left = 100;
  519.         rect.bottom = 32767;
  520.         rect.right = 32767;
  521.         lNewPoint = GrowWindow( pwin, point, &rect );
  522.         if( ! lNewPoint )
  523.           return 0L;
  524.         point.h = LOUSHORT(lNewPoint) - pointOld.h;
  525.         point.v = HIUSHORT(lNewPoint) - pointOld.v;
  526.         if( ! point.h && ! point.v )
  527.           return 0L;
  528.         swp.cx += point.h;
  529.         swp.cy += point.v;
  530.         swp.y  -= point.v;
  531.         WinSetMultWindowPos( (HAB)NULL, &swp, 1 );
  532.         return 0L;
  533.     }
  534.  
  535.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  536. }
  537.  
  538. /*-----------------------------------------------------------------*/
  539. /* Window function for the title bar window class.                 */
  540. /*-----------------------------------------------------------------*/
  541.  
  542. MRESULT EXPENTRY MpmFnwpTitleBar( hwnd, msg, mp1, mp2 )
  543.     HWND        hwnd;
  544.     USHORT      msg;
  545.     MPARAM      mp1;
  546.     MPARAM      mp2;
  547. {
  548.     Point       point, pointOld;
  549.     Rect        rect;
  550.     HWND        hwndFrame;
  551.     WindowPeek  pwin;
  552.     Str255      str;
  553.     PWNDPARAMS  pwprm;
  554.     USHORT      usLen;
  555.  
  556.     if( ! MpmValidateWindow(hwnd) )
  557.       return FALSE;
  558.  
  559.     switch( msg )
  560.     {
  561.       /* Let user move the window; notify it of new position */
  562.  
  563.       case WM_BUTTON1DOWN:
  564.         hwndFrame = MYWNDOF(hwnd).hwndOwner;
  565.         pwin = MYWNDOF(hwnd).pwin;
  566.         pointOld.h = (**pwin->contRgn).rgnBBox.left;
  567.         pointOld.v = (**pwin->contRgn).rgnBBox.top;
  568.         point.h = MOUSEMSG(&msg)->x;
  569.         point.v = _alSysVal[SV_CYSCREEN] - MOUSEMSG(&msg)->y;
  570.         /* should do a WM_QUERYMINMAXINFO... */
  571.         rect.top = 24;
  572.         rect.left = 4;
  573.         rect.bottom = _alSysVal[SV_CYSCREEN] - 4;
  574.         rect.right = _alSysVal[SV_CXSCREEN] - 4;
  575.         DragWindow( pwin, point, &rect );
  576.         point.h = (**pwin->contRgn).rgnBBox.left - pointOld.h;
  577.         point.v = (**pwin->contRgn).rgnBBox.top  - pointOld.v;
  578.         if( point.h || point.v )
  579.         {
  580.           MYWNDOF(hwndFrame).x += point.h;
  581.           MYWNDOF(hwndFrame).y -= point.v;
  582.           if( MYCLASSOF(hwndFrame).class.flClassStyle & CS_MOVENOTIFY )
  583.             WinSendMsg( hwndFrame, WM_MOVE, 0, 0 );
  584.         }
  585.         return 0L;
  586.  
  587.       /* Pick up the window text from the Mac and return it */
  588.  
  589.       case WM_QUERYWINDOWPARAMS:
  590.         pwprm = PVOIDFROMMP(mp1);
  591.         if( ! ( pwprm->fsStatus & (WPM_TEXT|WPM_CCHTEXT) ) )
  592.           return 0L;
  593.         GetWTitle( MYWNDOF(hwnd).pwin, (char*)str );
  594.         if( pwprm->fsStatus & WPM_TEXT )
  595.         {
  596.           usLen = pwprm->cchText;
  597.           if( usLen > (BYTE)str[0] )
  598.             usLen = (BYTE)str[0];
  599.           memcpy( pwprm->pszText, str+1, usLen );
  600.           pwprm->pszText[usLen] = '\0';
  601.         }
  602.         pwprm->cchText = usLen;
  603.         return MRFROMSHORT(1);
  604.  
  605.       /* Set the Mac's window text */
  606.  
  607.       case WM_SETWINDOWPARAMS:
  608.         pwprm = PVOIDFROMMP(mp1);
  609.         if( ! ( pwprm->fsStatus & WPM_TEXT ) )
  610.           return 0L;
  611.         usLen = pwprm->cchText;
  612.         if( usLen > 255 )
  613.           usLen = 255;
  614.         memcpy( str+1, pwprm->pszText, usLen );
  615.         str[0] = usLen;
  616.         SetWTitle( MYWNDOF(hwnd).pwin, (char*)str );
  617.         return MRFROMSHORT(1);
  618.     }
  619.     
  620.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  621. }
  622.  
  623. /*-----------------------------------------------------------------*/
  624.